<?php
namespace App\Controllers\Order;
use App\Models\Goods\Goods;
use App\Models\Order\Order;
use App\Models\Goods\GoodsAffiliate;
use App\Models\Coupons\Coupons;
use App\Models\Store\Store;
use App\Libs\Order\OrderList;

/**
*	获取订单数量算金额
*/
class GetOrderPrice extends \App\Libs\Base\BaseAction
{
    protected function beforeRun() {
        parent::beforeRun();
        $this->needLogin = TRUE;
    }
	
	public function execute(){
		$goods_id = (int)$this->request->get('goods_id');
		$goods_sum = (int)$this->request->get('goods_sum');
		
		if( $goods_id < 1 ){
			return \App\Libs\Views\Json::view(1, '传入的商品参数不正确', Null );	
		}
		if( $goods_sum < 1 ){
			return \App\Libs\Views\Json::view(1, '传入的商品数量不正确', Null );	
		}


			
		//商品信息
		$goods = Goods::find( array(
			' id = :gid:',
			"columns"=>"goods_name,sale_price",
			'bind'=>array( 'gid' => $goods_id )
		) );
		if( empty( $goods ) ){
			return \App\Libs\Views\Json::view(1, '未查找到相关商品信息', Null );
		}else{
			return \App\Libs\Views\Json::view(0, '获取信息成功', ['price'=>Goods::formatPrice( $goods_sum * $goods->sale_price ) ]) ;
		}
		
	}
}
